<?php
session_start();
include_once "../apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$medicalCareName = $_POST["medical_care_name"];
$medicalCareDetail = $_POST["medical_care_detail"];
$price = $_POST["price"];

$medicalCareId = $_GET["medical_care_id"];
if($medicalCareId == "" || $medicalCareId == null){
	$medicalCareId = $_POST["medical_care_id"];
}

$mode = $_GET["mode"];
if($mode == "" || $mode == null){
	$mode = $_POST["mode"];
}

$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}

if($mode == "insert"){
	$arrData["medical_care_name"] = "".$medicalCareName."";
	$arrData["medical_care_detail"] ="".$medicalCareDetail."";
	$arrData["price"] ="".$price."";
	$arrData["create_date"] = "".date("Y-m-d")."";
	$arrData["create_by"] = "".$_SESSION["user_name"]."";
	$managerIUDS->inserData($arrData, "medical_care");
	header("Location:../contents/medical_care_main.php");
}else if($mode == "delete"){
	$arrPrimaryKey["medical_care_id"] = "".$medicalCareId."";
	$managerIUDS->deleteData("medical_care", $arrPrimaryKey, "");
	header("Location:../contents/medical_care_main.php");
}else if($mode == "update"){
	$arrData["medical_care_name"] = "".$medicalCareName."";
	$arrData["medical_care_detail"] ="".$medicalCareDetail."";
	$arrData["price"] ="".$price."";
	$arrData["update_date"] = "".date("Y-m-d")."";
	$arrData["update_by"] = "".$_SESSION["user_name"]."";
	$arrPrimaryKey["medical_care_id"] = "".$medicalCareId."";
	$managerIUDS->updateData($arrData, "medical_care", $arrPrimaryKey, "");
	header("Location:../contents/medical_care_main.php");
}else if($mode == "search"){
	$medicalCareName = $_GET["medical_care_name"];
	header("Location:../contents/medical_care_main.php?mode=search&page=".$page."&medical_care_name=".urlencode($medicalCareName));
}else if($mode == "listMedicalCareData"){
	$medicalCareData = array();
	$medicalCareName = $_GET["medical_care_name"];
	if($medicalCareName == "" || $medicalCareName == null){
		$medicalCareName = $_POST["medical_care_name"];
	}
	$medicalCareData = $managerIUDS->queryData("medical_care_name", "medical_care", " WHERE medical_care_name LIKE '%".$medicalCareName."%'", "2", "");
	echo json_encode($medicalCareData);

}
?>